﻿// owner 蒋家伟

#pragma once
// std
#include <unordered_map>

// jsdk
#include "ObjectReflectDefine.h"
#include "UniqueId.h"
#include "DBSchemaObject.h"
#include "FieldReflectManager.h"

namespace jsdk
{
    struct ClassDescriptor
    {
        ClassDescriptor(const UniqueId& uniqueId, const std::wstring& classTypeName, const reflectFun& reflectfun);
        reflectFun              ReflectFun;
        FieldReflectManager     FieldReflectMgr;
    };

    class ObjectReflectFactory
    {
    public:
        static ObjectReflectFactory& get();

        ~ObjectReflectFactory();

        /// \ brief 注册反射对象函数
        /// \ in uniqueId       类别uid标识
        /// \ in classTypeName  类别名称
        /// \ in reflectfun     反射函数
        /// \ return true表示注册成功
        bool registerReflectClassDescriptor(const UniqueId& uniqueId, const std::wstring& classTypeName , const reflectFun& reflectfun);

        /// \ 获取反射对象
        /// \ in uniqueId       类别uid标识
        /// \ return 反射的schema对象
        OwnerPtr<DBSchemaObject> getReflectObject(const UniqueId& uniqueId) const;

        /// \ 获取字段描述管理器
        /// \ in uniqueId        类别uid标识
        /// \ return IFieldReflectManager字段管理器
        FieldReflectManager* getFieldReflectManager(const UniqueId& uniqueId, void* pClassAddress);

    private:
        std::unordered_map<UniqueId, OwnerPtr<ClassDescriptor>, Hash_UniqueId> m_uidToObjectUmap;
    };
}
